package com.knight.jdk8.optional;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * @Description:
 * @author: knight
 * @Date: 2019-04-24 21:58
 */
public class OptionalTest2 {
    public static void main(String[] args) {
        Employee employee1 = new Employee();
        employee1.setName("zhangsan");

        Employee employee2 = new Employee();
        employee2.setName("lisi");

        Company company = new Company();
        company.setName("company1");
        List<Employee> employees = Arrays.asList(employee1, employee2);
      //  company.setEmployeeList(employees);


        // 如果company类的employeeList属性为空则返回一个空集合否则返回当前的集合
        Optional<Company> optionalCompany = Optional.ofNullable(company);
        System.out.println(optionalCompany.map(otherCompany -> otherCompany.getEmployeeList()).orElse(Collections.emptyList()));



    }
}
